!** Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
!** See https://llvm.org/LICENSE.txt for license information.
!** SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

!*  Test intrinsics function abs with quad precision complex arrays.

program main
  use check_mod
  implicit none
  real*16, parameter :: maxr16 = sqrt(huge(1.0_16))
  real*16, parameter :: minr16 = tiny(1.0_16)
  !Maximum, Zero, Zero, Random number, Minimum.
  complex(kind=16), parameter :: t1(4) = [(0.0_16,maxr16), (0.0_16,0.0_16),&
                    (-0.0_16, -0.0_16),&
                    (-1746375634.27634756437627364767623234E+2000_16, &
                     9832.2343767236434348778783245433323E+2300_16)]
  !Maximum, Zero, Zero, Random number, Minimum.
  complex(kind=16), parameter :: t2(2,2) = reshape([(0.0_16,maxr16), (0.0_16,0.0_16),&
                    (-0.0_16, -0.0_16),&
                    (-1746375634.27634756437627364767623234E+2000_16, &
                     9832.2343767236434348778783245433323E+2300_16)], (/2,2/))

  real(kind=16), parameter :: t3(4) = abs(t1)
  real(kind=16), parameter :: t4(2,2) = abs(t2)
  real(kind=16) :: t5(4) = abs(t1)
  real(kind=16) :: t6(2,2) = abs(t2)
  type mytype
    complex(kind=16) :: m
    complex(kind=16) :: marr(5)
  end type
  type(mytype) :: dt(5)

  real(kind=16), dimension(34) :: rslt, expect

  expect = [1.09074813561941592946298424473378276E+2466_16, 0.0_16, 0.0_16,&
            9.83223437672364343487787832454333215E+2303_16,&
            1.09074813561941592946298424473378276E+2466_16, 0.0_16, 0.0_16,&
            9.83223437672364343487787832454333215E+2303_16,&
            1.09074813561941592946298424473378276E+2466_16, 0.0_16, 0.0_16,&
            9.83223437672364343487787832454333215E+2303_16,&
            1.09074813561941592946298424473378276E+2466_16, 0.0_16, 0.0_16,&
            9.83223437672364343487787832454333215E+2303_16,&
            1.09074813561941592946298424473378276E+2466_16, 0.0_16, 0.0_16,&
            9.83223437672364343487787832454333215E+2303_16,&
            1.09074813561941592946298424473378276E+2466_16, 0.0_16, 0.0_16,&
            9.83223437672364343487787832454333215E+2303_16,&
            1.09074813561941592946298424473378276E+2466_16, 0.0_16, 0.0_16,&
            9.83223437672364343487787832454333215E+2303_16,&
            4.75473186308633355902452847925549301E-4932_16,&
            1.09074813561941592946298424473378276E+2466_16, 0.0_16, 0.0_16,&
            9.83223437672364343487787832454333215E+2303_16,&
            4.75473186308633355902452847925549301E-4932_16]

  dt(:)%m = [(0.0_16,maxr16), (0.0_16,0.0_16), (-0.0_16, -0.0_16),&
             (-1746375634.27634756437627364767623234E+2000_16, &
              9832.2343767236434348778783245433323E+2300_16), &
             (minr16, minr16)]
  dt(2)%marr(:) = [(0.0_16,maxr16), (0.0_16,0.0_16), (-0.0_16, -0.0_16),&
                   (-1746375634.27634756437627364767623234E+2000_16, &
                    9832.2343767236434348778783245433323E+2300_16), (minr16, minr16)]


  rslt(1:4) = abs(t1)
  rslt(5:8) = reshape(abs(t2), (/4/))
  rslt(9:12) = t3
  rslt(13:16) = reshape(t4, (/4/))
  rslt(17:20) = t5
  rslt(21:24) = reshape(t6, (/4/))
  rslt(25:29) = abs(dt(:)%m)
  rslt(30:34) = abs(dt(2)%marr(:))
  call checkr16(rslt, expect, 34, rtoler = 1.0E-33_16)
end program
